home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip: 2001 Haziran
/
CHIP Haziran2001.iso
/
prog
/
share
/
04
/
setup.exe
/
MM9.Cab
/
F1490_utils.runtime5.asp.9B3B646D_CB56_4EAE_BAB7_3E7E8E41A649
< prev
next >
Wrap
Text File
|
2000-08-17
|
20KB
|
636 lines
<% Response.Buffer = true %>
<SCRIPT runat="server" language="JScript">
// *****************************************************************************
//
// include/utils.runtime5.asp
//
// Dynamic Link utilities for ASP.
//
// COPYRIGHT (c) 1999-2000 Adobe Systems Incorporated. All rights reserved.
// *****************************************************************************
// CONTENT SOURCE WRAPPERS
//
// GoLive supports a standard interface definition for a content source. Other
// objects are wrapped in this interface to allow access.
//
// Content Source Wrapper Properties:
//
// RecordCount
// the number of records in the recordset
// AbsolutePosition
// the (1-based) index of the current record (the cursor position)
// EOF
// true if the cursor is after the last record
//
// Content Source Wrapper Methods:
//
// Move(delta)
// moves the cursor by the specified amount
// MoveFirst()
// moves the cursor to the first record
// MoveNext()
// moves the cursor to the next record
//
// Value(fieldName)
// returns the value of a field of the current record
// Set(fieldName, value)
// sets the value of a field of the current record
//
// UpdateBatch()
// performs any required action to update the datasource after the
// records have been changed (ie: store back to the database)
//
// Optional Content Source Wrapper Methods:
//
// Key()
// returns a key indentifying the current record
//
// *****************************************************************************
// Runtime Debug Switch
//
// false(default) or true
var RuntimeDebug = false; // true or false (default)
// -----------------------------------------------------------------------------
// Methods shared by many Content Source Wrappers.
function CSW_Move( delta )
{
this.AbsolutePosition += delta;
this.EOF = ( this.AbsolutePosition > this.RecordCount );
}
function CSW_MoveFirst()
{
this.AbsolutePosition = 1;
this.EOF = ( this.AbsolutePosition > this.RecordCount );
}
function CSW_MoveNext()
{
this.Move( 1 );
}
function CSW_NOP()
{
}
// *****************************************************************************
// UTILITY FUNCTIONS
//
// -----------------------------------------------------------------------------
// Get the database path. The only tricky part is finding the path to the
// database folder. The algorithm is to search for the #include of
// include/ado.runtime5.asp in the current file. If you'd like to set custom path
// out of config folder, you can change as following:
// return "C:\\databasefolder\\";
function GetDatabasePath()
{
var fileSystem = new ActiveXObject( "Scripting.FileSystemObject" );
var databasePath = "";
var pathTranslated = String( Request.ServerVariables( "PATH_TRANSLATED" ));
if( 0 <= pathTranslated.indexOf( "parseasp.asp" )){ // for Server.Transfer()
databasePath = Server.MapPath(".") + "/../databases/";
}else{
var currentFile = fileSystem.OpenTextFile( pathTranslated );
var matchExpression = /\s*[<]!--\s*#INCLUDE\s+(FILE|VIRTUAL)="(.*)[\/]include[\/]utils.runtime5.asp"\s*--[>]/;
while( !currentFile.AtEndOfStream ){
if( matchExpression.exec( currentFile.ReadLine() )){
break;
}
}
if( currentFile.AtEndOfStream ){
return "";
}
if( RegExp.$1 == "FILE" ){
databasePath = Server.MapPath( "." )
+ "/" + RegExp.$2 + ( RegExp.$2 != "" ? "/":"" )
+ "databases/";
} else {
databasePath = Server.MapPath( RegExp.$2 ) + ( RegExp.$2 != "" ? "/":"" )
+ "databases/";
}
}
return databasePath;
}
// -----------------------------------------------------------------------------
// Get the connection string for a database.
function ConnectString( db ){ return GetConnectString( db ); } // version 1.0 compatibility
function GetConnectString( db )
{
var fileSystem = new ActiveXObject( "Scripting.FileSystemObject" );
var databasePath = GetDatabasePath();
if( databasePath == "" ) return;
databasePath += db;
if( fileSystem.FileExists( databasePath + ".udl" )){
return "File Name=" + databasePath + ".udl";
}else if( fileSystem.FileExists( databasePath + ".dsn" )){
return "FILEDSN=" + databasePath + ".dsn";
}else if( fileSystem.FileExists( databasePath + ".mdb" )){
return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databasePath + ".mdb";
}else if( fileSystem.FileExists(databasePath + ".xdb" )){
return "DSN=" + fileSystem.GetBaseName( databasePath );
}else{
return "";
}
}
// *****************************************************************************
// DYNAMIC LINKING
// -----------------------------------------------------------------------------
// Add a URLArgs function to the list of functions to be called by the standard
// URLArgs().
var URLArgsFunctionList = new Array;
function RegisterURLArgsFunction( functionRef )
{
URLArgsFunctionList[URLArgsFunctionList.length] = functionRef;
}
// -----------------------------------------------------------------------------
// Add query parameters to a href. The first set comes from known parameters
// that must be passed by application servers. The second is specified by
// the arguments to the function (which must be name/value pairs)
function URLArgs()
{
var args = new Array;
var oldArgs = queryStringToArray( Request.QueryString.Item );
for( var x in oldArgs ){
if( x == "mscssid" ){ // add other known parameters here using ||
args[x] = oldArgs[x];
}
}
for( var i = 0; i < arguments.length; i += 2 ){
args[Server.URLEncode( arguments[i] )] = Server.URLEncode( arguments[i + 1] );
}
if( typeof(URLArgsFunctionList ) != "undefined" ){
for( var f = 0; f < URLArgsFunctionList.length; f++ ){
var moreArgs = URLArgsFunctionList[f]();
for( var x in moreArgs ){
args[x] = moreArgs[x];
}
}
}
return queryArrayToString( args );
}
// -----------------------------------------------------------------------------
// Split up a string of the form "arg1=val1&...&argN=valN" into an array
// of argument value pairs.
function queryStringToArray( queryString )
{
if( queryString == "" ){
return new Array;
}
var queryArray = new Array;
var args = queryString.split( "&" );
for( var i = 0; i < args.length; i++ ){
var pair = args[i].split( "=" );
queryArray[pair[0]] = pair[1];
}
return queryArray;
}
// -----------------------------------------------------------------------------
// Construct a query string from an array of key value pairs.
function queryArrayToString( queryArray )
{
var args = new Array;
var i = 0
for( var x in queryArray ){
if( queryArray[x] == null ){
args[i] = x;
}else{
args[i] = x + "=" + queryArray[x];
}
i++;
}
return args.join( "&" );
}
// -----------------------------------------------------------------------------
// Turn an application-relative path into a file-relative path
function mapPath( path )
{
var ups = -2; // lose one for relative path, one for current directory
var curPath = "" + Request.ServerVariables( "PATH_INFO" );
for( var i = 0; i < curPath.length; i++ ){
if( curPath.charAt( i ) == '/' || curPath.charAt( i ) == '\\' ){
ups++;
}
}
var upPath = "";
for( var i = 0; i < ups; i++ ){
upPath += "../"
}
return upPath + path;
}
// -----------------------------------------------------------------------------
// Turn an relative path into an absolute path
function absolutePath(basePath, relativePath)
{
if (String(relativePath).charAt(0) == '/') {
return relativePath;
}
var origurl = String( basePath ).split( "?" );
var newurl = String( relativePath ).split( "?" );
var origparts = String( origurl[0] ).split( "/" );
var newparts = String( newurl[0] ).split( "/" );
var origargs;
if( origurl.length > 1 ){
origargs = String( origurl[1] ).split( "&" );
}else{
origargs = new Array();
}
var newargs;
if( newurl.length > 1 ){
newargs = String( newurl[1] ).split( "&" );
}else{
newargs = new Array();
}
var finalparts;
var part = new String( newparts[0] );
if( part.charAt( part.length - 1 ) == ":" ) { // absolute href
finalparts = newparts;
}else{
origparts = origparts.slice( 0, -1 ); // first we'll get rid of the last part
while( newparts[0] == ".." ){
origparts = origparts.slice( 0, -1 ); // get rid of the last part
newparts = newparts.slice( 1 ); // get rid of the ".."
}
finalparts = origparts.concat( newparts );
}
var finalargs = origargs.concat( newargs );
return finalparts.join( "/" ).concat( "?" ).concat( finalargs.join( "&" ));
}
// -----------------------------------------------------------------------------
// Add arguments to a url. New values replace old values.
function addArgs( url, newArgs )
{
var urlString = String( url );
if( newArgs == "" ){
return urlString;
}
var i = urlString.indexOf( "?" );
if( i == -1 ){
return urlString + "?" + newArgs;
}
var urlBase = urlString.substr( 0, i );
var oldArgs = urlString.substr( i + 1 );
var values = queryStringToArray( oldArgs );
var newValues = queryStringToArray( newArgs );
for( var x in newValues ){
values[x] = newValues[x];
}
return urlBase + "?" + queryArrayToString( values );
}
// *****************************************************************************
// RECORD NAVIGATION
//
// These functions support "prev" and "next" links on record-oriented content
// sources.
//
// -----------------------------------------------------------------------------
// Get current RECORD_INDEX. It returns URL parameter, AbsolutePosition or 1 as default.
// If BlockSize is not set, it returns 1.
function GetRecordIndex( contentSource )
{
var recordIndex = 1;
if( Request.QueryString( "RECORD_INDEX" ).Count >= 1 ){
recordIndex = Number( Request.QueryString( "RECORD_INDEX" ));
}else{
if( typeof( contentSource ) != "undefined" ){
if( 0 == contentSource.BlockSize ) recordIndex = contentSource.AbsolutePosition;
else recordIndex = 1;
}
}
return recordIndex;
}
// -----------------------------------------------------------------------------
// Remove URL parameter from URL string
function removeUrlParameter( urlString, removeParameter )
{
var returnString = "";
var x = urlString.indexOf( removeParameter );
if( 0 <= x ){
if( 0 <= x ){
returnString = urlString.substr( 0, x-1 ); // stuff before parameter
}
var y = urlString.indexOf( "&", x );
if( 0 < y ){
returnString += "&" + urlString.substr( y+1 ); // stuff after parameter
}
}else{
returnString = urlString;
}
return returnString;
}
// -----------------------------------------------------------------------------
// Create a link to the current page with a specified record index, preserving
// all other query parameters.
function linkToRecord( contentSource, index )
{
var href = Request.ServerVariables( "URL" ) + "?RECORD_INDEX=" + index;
var queryString = String( Request.QueryString );
queryString = removeUrlParameter( queryString, "$key" );
queryString = removeUrlParameter( queryString, "RECORD_KEY" );
for( var i = 0; i < contentSource.PrimaryKey.length; i++ ) queryString = removeUrlParameter( queryString, contentSource.PrimaryKey[i] );
var a = queryString.indexOf( "RECORD_INDEX" );
if( a == -1 ){
a = queryString.indexOf( "RECORD%5FINDEX" ); // URL-encoded '_'
}
if( a == -1 ){
href += "&" + queryString;
}else{
if( a > 0 ){
href += "&" + queryString.substr( 0, a-1 ); // stuff before RECORD_INDEX
}
var b = queryString.indexOf( "&", a );
if( b > 0 ){
href += "&" + queryString.substr( b+1 ); // stuff after RECORD_INDEX
}
}
return " href=\"" + href + "\"";
}
// -----------------------------------------------------------------------------
// Create a link to the prevoius record in a record-oriented content source.
function LinkToPreviousRecord( contentSource )
{
var current = GetRecordIndex( contentSource );
var index = current - ( 0 == contentSource.BlockSize ? 1 : contentSource.BlockSize );
if( contentSource.RecordCount < index ) index = contentSource.RecordCount;
if( index < 1 ) return ""; // disable link...
else return linkToRecord( contentSource, index );
}
// -----------------------------------------------------------------------------
// Create a link to the next record in a record-oriented content source.
function LinkToNextRecord( contentSource )
{
var current = GetRecordIndex( contentSource );
var index = current + ( 0 == contentSource.BlockSize ? 1 : contentSource.BlockSize );
if( index < 1 ) index = 1;
if( contentSource.RecordCount < index ) return ""; // disable link...
else return linkToRecord( contentSource, index );
}
// -----------------------------------------------------------------------------
// Create a link to a new record in a record-oriented content source.
function LinkToNewRecord(contentSource)
{
return linkToRecord( contentSource, contentSource.RecordCount + 1 );
}
// -----------------------------------------------------------------------------
// Create a link to the first record in a record-oriented content source.
function LinkToFirstRecord( contentSource )
{
var current = GetRecordIndex( contentSource );
if( current <= 1 ) return ""; // disable link...
else return linkToRecord( contentSource, 1 );
}
// -----------------------------------------------------------------------------
// Create a link to the last record in a record-oriented content source.
function LinkToLastRecord( contentSource )
{
var current = GetRecordIndex( contentSource );
var index = contentSource.RecordCount;
if( 0 < contentSource.BlockSize ) index = Math.floor( contentSource.RecordCount / contentSource.BlockSize ) * contentSource.BlockSize + 1;
if(( index <= current )||( contentSource.RecordCount < index )) return ""; // disable link...
else return linkToRecord( contentSource, index );
}
// *****************************************************************************
// MISCELLANEOUS
function Selected( condition )
{
if( condition ){
return "selected";
}else{
return "";
}
}
function Checked( condition )
{
if( condition ){
return "checked";
}else{
return "";
}
}
// *****************************************************************************
// HTML ENCODING/DECODING FOR VBSCRIPT
function encodeHTML( text )
{
return urlencode( text );
}
function decodeHTML( text )
{
return unescape( text );
}
// -----------------------------------------------------------------------------
// Encode a string in application/x-www-form-urlencoded form. TODO: this
// function leaves somes non-alphanumeric characters unencoded, but it
// correctly encodes '+', '&', and '=', and so works correctly with the
// ASP query string decoding.
function urlencode( text )
{
var encodedText = escape( text );
encodedText = encodedText.replace( /\+/g, "%2B" );
return encodedText;
}
// *****************************************************************************
// SECURITY
function RejectUnauthorizedCallers()
{
var caller = String( Request.ServerVariables( "REMOTE_ADDR" )).split( "." );
var fso = Server.CreateObject( "Scripting.FileSystemObject" );
var currentFile = fso.OpenTextFile( Request.ServerVariables( "PATH_TRANSLATED" ));
var matchExpression = /\s*[<]!--\s*#INCLUDE\s+(FILE|VIRTUAL)="(.*)[\/]include[\/]utils.runtime5.asp"\s*--[>]/;
while(!currentFile.AtEndOfStream) {
if(matchExpression.exec( currentFile.ReadLine() )) {
var friendsPath;
if( RegExp.$1 == "FILE" ){
friendsPath = Server.MapPath( "." ) + "/" + RegExp.$2
+( RegExp.$2 != "" ? "/":"" )
+ "include/friends.asp";
}else{
friendsPath = Server.MapPath( RegExp.$2 )
+( RegExp.$2 != "" ? "/":"" )
+ "include/friends.asp";
}
if( fso.FileExists( friendsPath )){
var ts = fso.OpenTextFile( friendsPath, 1 ); // forReading
while( !ts.AtEndOfStream ){
var line = ts.ReadLine();
if(( line.length == 0 )||( line.charAt( 0 ) == ";" )||( line.charAt( 0 ) == "<" )){
continue;
}
var splitline = line.split(/\s/);
var kosherAddr = splitline[0].split( "." );
var kosherMask = ( splitline.length > 1 ) ? splitline[1].split( "." ) : new Array( 255, 255, 255, 255 );
var kosher = true;
var i;
for( i in caller ) {
if(kosherAddr[i] != ( caller[i] & kosherMask[i] )) {
kosher = false;
break;
}
}
if( kosher ){
return;
}
}
}else if(( caller[0] == 127 )&&( caller[1] == 0 )&&( caller[2] == 0 )&&( caller[3] == 1 )){
return;
}
break;
}
}
Response.Status = "403 Forbidden";
Response.Write( "You are not authorized to access this page. Check with your Web administrator to make sure your machine is listed in the include/friends.asp file." );
Response.End();
}
// *****************************************************************************
// For version 1.0 compatibility
function linkToPreviousRecord( contentSource ){ return LinkToPreviousRecord( contentSource ); }
function linkToNextRecord( contentSource ){ return LinkToNextRecord( contentSource ); }
function linkToNewRecord( contentSource ){ return LinkToNewRecord( contentSource ); }
function linkToFirstRecord( contentSource ){ return LinkToFirstRecord( contentSource ); }
function linkToLastRecord( contentSource ){ return LinkToLastRecord( contentSource ); }
function selected( condition ){ return Selected( condition ); }
function checked( condition ){ return Checked( condition ); }
// *****************************************************************************
// Runtime Debug Message
function RuntimeDebugMessage( msg )
{
Response.Write( "<b><font color=\"red\">Runtime Error: " + msg + "</font></b><br>\n" );
return;
}
</SCRIPT>
<SCRIPT runat="server" language="VBScript">
' -----------------------------------------------------------------------------
' Pick a random element from a comma separated list of choices.
function random(choices)
Randomize
choices = choices & ","
choice = ""
n = 0
p = 1
while p <> -1
q = InStr(p, choices, ",")
if q <> 0 then
n = n + 1
if Rnd() < 1/n then
choice = Mid(choices, p, q - p)
end if
p = q + 1
else
p = -1
end if
wend
random = choice
end function
' -----------------------------------------------------------------------------
' VBScript style DateTime format conversion for calling from JScript
' return string type
function callVBFormatDateTime( dateField )
callVBFormatDateTime = FormatDateTime( dateField.Value, 0 )
end function
' -----------------------------------------------------------------------------
' Encode single/double quotation mark as HTML encode
function fixHTMLquotes( text )
if IsNull( text ) then
fixHTMLquotes = ""
else
temp = Replace( text, """", """ )
fixHTMLquotes = Replace( temp, "'", "'" )
end if
end function
' -----------------------------------------------------------------------------
</SCRIPT>